<template>
  <div class="reportFormPage">
    <div id="domid" class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">水泥混凝土抗弯拉强度试验检测报告</div>
        <div class="codeText">
          <tr>
            BGLQ05002F
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>报告编号：</span>
          <span class="placeholder">{{ form.baogbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>

            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <!--                <span>；来样时间：</span>-->
                <!--                <span :class="{ 'placeholder':!form.yangpsj }">{{ form.yangpsj }}</span>-->
              </td>
            </tr>

            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <el-input type="textarea" v-model="form.jiancyj" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="550px" class="middle-table">
          <tbody>
            <tr trindex="0" height="25" width="100%">
              <!--              223212-->
              <td width="15%" colspan="2" height="30">设计强度等级</td>
              <td width="17%" colspan="2" height="30">{{ form.shejqddj }}</td>
              <td width="25%" colspan="3" height="30">拌合方式</td>
              <td width="16%" colspan="2" height="30">{{ form.banhfs }}</td>
              <td width="11%" height="30">支座间距(mm)</td>
              <td width="16%" colspan="2" height="30">{{ form.zhizjj }}</td>
            </tr>

            <tr trindex="1" height="25">
              <td width="15%" colspan="2" height="30">成型方法</td>
              <td width="20%" colspan="2" height="30">{{ form.chengxff }}</td>
              <td width="15%" colspan="3" height="30">养护方法</td>
              <td width="20%" colspan="2" height="30">{{ form.yanghff }}</td>
              <td width="11%" colspan="1" height="30">坍落度(mm)</td>
              <td width="16%" colspan="2" height="30">{{ form.tanld }}</td>
            </tr>

            <tr height="50">
              <td colspan="2" rowspan="2" width="15%">试件编号</td>
              <td colspan="2" rowspan="2" width="17%">制件日期</td>
              <td colspan="2" rowspan="2" width="17%">试验日期</td>
              <td rowspan="2" width="8%">龄期(d)</td>
              <td colspan="2" rowspan="2" width="17%">试件尺寸(mm)</td>
              <td colspan="2" width="16%">抗弯拉强度(MPa)</td>
              <td rowspan="2" width="10%">结果判定</td>
            </tr>
            <tr height="25">
              <td width="8%">单值</td>
              <td width="8%">平均</td>
            </tr>
            <tr trindex="0" width="100%" v-for="(e, index) in form.detailList" :key="index">
              <td colspan="2" width="17%">{{ e.shijbh }}</td>
              <td colspan="2" rowspan="3" v-if="index % 3 == 0" width="17%">{{ e.zhizrq }}</td>
              <td colspan="2" rowspan="3" v-if="index % 3 == 0" width="17%">{{ e.shiyrq }}</td>
              <td rowspan="3" v-if="index % 3 == 0" width="8%">{{ e.lingq }}</td>
              <td rowspan="3" colspan="2" v-if="index % 3 == 0" width="17%">
                <span>{{ e.shijcc }}</span>
              </td>
              <td width="8%">{{ e.kangwlqddz }}</td>
              <td rowspan="3" v-if="index % 3 == 0" width="8%">{{ e.kangwlqdpj }}</td>
              <td rowspan="3" v-if="index % 3 == 0" width="10%">{{ e.jiegpd }}</td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="100px" class="bottom-table">
          <tbody>
            <tr>
              <td style="border-bottom-width: 1px">
                <span v-if="isPdf" class="textarea-span">{{ form.jiancjl }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.jiancjl" @focus="handleFocus('jiancjl')" @dblclick.native="getJcjl()" />
              </td>
            </tr>
            <tr>
              <td>
                <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">审核：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">批准：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block; margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import { handleFocus, emptyConvert, uniqueStr } from "@/views/reportForms/utils";
import decimal from "@/utils/big-decimal";
import { getSnhntKwlqdbgBsInfo } from "@/api/reportsnhnt/snhntKwlqdbgBsInfo";
import Bus from "@/utils/bus";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";

export default {
  name: "bhw",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  data() {
    return {
      lingq: undefined,
      options: [
        { value: 3, label: "3" },
        { value: 7, label: "7" },
        { value: 28, label: "28" }
      ],
      jilbh: "",
      form: {
        shejqddj: "",
        gongcbwyt: "",
        baogbh: "",
        jiancdwmc: "",
        totalPage: "",
        page: "",
        jiancyj: "",
        zhuyyqsbmcjbh: "",
        gongcmc: "",
        yangpmc: "",
        yangpbh: "",
        laiysj: "",
        yangpsl: "",
        yangpzt: ""
      },
      twoTableData: {},
      threeTableData: {},
      jiancjl: "检测结论：",
      fjsm: "附加声明：",
      dateText: "2024年05月10日",
      readonly: false
    };
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    syType: {
      type: [String, Number],
      default: () => ""
    }
  },
  watch: {},
  mounted() {
    //传递form表单值。
    Bus.$on("setkwlqdbgform", (data) => {
      const arr = ["shejqddj", "banhfs", "zhizjj", "chengxff", "yanghff", "tanld"];
      arr.forEach((item) => {
        this.form[item] = data[item];
      });
      this.$forceUpdate();
    });
    // 抗压强度列表
    Bus.$on("setSnhntkwlqdList", (data) => {
      this.form.detailList = data;
    });
    // 检测依据
    Bus.$on("setSnhntkwlBgJiancyj", (data) => {
      const { jiancyj, jiancyjIds } = data;
      const str = jiancyj + (this.form.jiancyj ? "、" + this.form.jiancyj : "");
      const ids = jiancyjIds + (this.form.jiancyjIds ? "," + this.form.jiancyjIds : "");
      this.form.jiancyj = uniqueStr(str, "、");
      this.form.jiancyjIds = uniqueStr(ids, ",");
    });
    // 主要设备
    Bus.$on("setSnhntkwlBgZhuyyqsbmcjbh", (data) => {
      const { zhuyyqsbmcjbh, shebIds } = data;
      const str = zhuyyqsbmcjbh + (this.form.zhuyyqsbmcjbh ? "、" + this.form.zhuyyqsbmcjbh : "");
      const ids = shebIds + (this.form.shebIds ? "," + this.form.shebIds : "");
      this.form.zhuyyqsbmcjbh = uniqueStr(str, "、");
      this.form.shebIds = uniqueStr(ids, ",");
    });
    // 各报表给报告传值
    Bus.$on("setYansBgJiancjg", (data) => {
      if (data.length <= 0) {
        return;
      }
      let count = 0;
      data.forEach((item) => {
        if (this.form.baDetailVos[item.key].jiancjg == item.value) {
          count++;
        }
      });

      if (count == data.length) {
        return;
      }
      let keys = [];
      let flg = false;
      data.forEach((item) => {
        this.form.baDetailVos[item.key].jiancjg = item.value;
        if (!flg && this.form.baDetailVos[item.key].symbolValue) {
          flg = true;
        } else {
          this.form.baDetailVos[item.key].jiegpd = "实测值";
        }
        keys.push(item.key);
      });
      if (flg) {
        this.computeDetectionResult(keys);
      }
    });
  },
  beforeDestroy() {
    // 或者你可以使用其他合适的生命周期钩子
    // 停止监听事件
    Bus.$off("setkwlqdbgform");
    Bus.$off("setSnhntkwlBgJiancyj");
    Bus.$off("setSnhntkwlBgZhuyyqsbmcjbh");
    Bus.$off("setYansBgJiancjg");
  },
  created() {
    this.getInfo();
  },
  methods: {
    getInfo() {
      // if (!this.excelId) {
      //   return;
      // }
      getSnhntKwlqdbgBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.jiancjl) {
          this.form.jiancjl = "检测结论：";
        }
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },
    submitForm() {
      return this.form;
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
      this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      // this.$set(this.form, 'jiancyj', info.label);
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    handlekangyqd(e) {
      if (e.jixzh) {
        e.kangyqd = ((1.35 * e.jixzh * 1000) / 4998.49).toFixed(1);
      } else {
        e.kangyqd = undefined;
      }
      return e.kangyqd;
    },
    //生成检测结论
    getJcjl() {
      // 检测结论:经检测，28天抗折强度分别达到设计强度的170.49、163.8%，符合设计要求。
      //拼接占百分比
      let dadsjqd = "";
      console.log("dajllsdl------------------0-------------------", this.form.detailList);
      this.form.detailList.forEach((e) => {
        if (e.lingq == 28 && !dadsjqd.includes(e.zhansjqdbfb)) {
          dadsjqd = dadsjqd + e.zhansjqdbfb + "%、";
        }
      });
      console.log("dajllsdl------------------1-------------------", dadsjqd);
      if (dadsjqd) {
        dadsjqd = dadsjqd.substring(0, dadsjqd.length - 1);
      }
      console.log("dajllsdl---------------2----------------------", dadsjqd);
      this.form.jiancjl = "检测结论：经检测，28天抗折强度分别达到设计强度的" + dadsjqd + "，符合设计要求。";
    },

    // 编号处理
    handleshijbh(index) {
      return Math.ceil(index / 3).toString() + "-" + (index % 3 == 0 ? 3 : index % 3).toString();
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    }
  }
};
</script>

<style scoped lang="scss">
</style>
